<?php defined('SYSPATH') OR die('No direct script access.');

class Controller_Wizard extends Controller_Base {

	public function before()
	{
		parent::before();

		$ip = $_SERVER['REMOTE_ADDR'];
		if (empty($ip) || !ip_in_subnet('127.0.0.1/24', $ip)) //本机方可修改密码
			return $this->failure('tools.failure_ip_invail');
	}

	public function action_index()
	{
		$this->template->_table_list = Model::instance('wizard')->get_table_list();
		$this->template->set_filename('smarty3:system/wizard');
	}

	public function action_fields()
	{
		$keys = 'model_name,table_name,subtable_name';
		$data = Validate::instance()->get_post_data($keys,'wizard/edit');
		if (!empty($data['error']))
			return $this->failure_post($data['error']);

		$this->template->_column_list = Model::instance('wizard')->get_column_list($data['data']['table_name'], $data['data']['subtable_name']);
		$this->template->_table_name = $table_name;
		$this->template->_subtable_name = $subtable_name;

		$this->template->set_filename('smarty3:system/wizard_fields');
	}

}